package com.ruoyi.boat.controller;

import com.ruoyi.boat.aop.AvoidDuplicate;
import com.ruoyi.boat.domain.PathPoint;
import com.ruoyi.boat.service.IPathPointService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 路径点Controller
 * 
 * @author ruoyi
 * @date 2023-08-01
 */
@Controller
@RequestMapping("/boat/pathPoint")
public class PathPointController extends BaseController
{
    private String prefix = "boat/pathPoint";

    @Autowired
    private IPathPointService pathPointService;

    @RequiresPermissions("boat:pathPoint:view")
    @GetMapping()
    public String pathPoint()
    {
        return prefix + "/pathPoint";
    }

    /**
     * 查询路径点列表
     */
    @RequiresPermissions("boat:pathPoint:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PathPoint pathPoint)
    {
        startPage();
        List<PathPoint> list = pathPointService.selectPathPointList(pathPoint);
        return getDataTable(list);
    }

    /**
     * 导出路径点列表
     */
    @RequiresPermissions("boat:pathPoint:export")
    @Log(title = "路径点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(PathPoint pathPoint)
    {
        List<PathPoint> list = pathPointService.selectPathPointList(pathPoint);
        ExcelUtil<PathPoint> util = new ExcelUtil<PathPoint>(PathPoint.class);
        return util.exportExcel(list, "路径点数据");
    }

    /**
     * 新增路径点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存路径点
     */
    @RequiresPermissions("boat:pathPoint:add")
    @Log(title = "路径点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PathPoint pathPoint)
    {
        return toAjax(pathPointService.insertPathPoint(pathPoint));
    }

    /**
     * 修改路径点
     */
    @RequiresPermissions("boat:pathPoint:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PathPoint pathPoint = pathPointService.selectPathPointById(id);
        mmap.put("pathPoint", pathPoint);
        return prefix + "/edit";
    }

    /**
     * 修改保存路径点
     */
    @RequiresPermissions("boat:pathPoint:edit")
    @Log(title = "路径点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PathPoint pathPoint)
    {
        return toAjax(pathPointService.updatePathPoint(pathPoint));
    }

    /**
     * 删除路径点
     */
    @RequiresPermissions("boat:pathPoint:remove")
    @Log(title = "路径点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pathPointService.deletePathPointByIds(ids));
    }
}
